package com.ddz.shortcut

import android.accessibilityservice.AccessibilityService
import android.view.accessibility.AccessibilityEvent
import com.ddz.shortcut.utils.JKShortcutLog
import kotlin.system.measureTimeMillis

object JKShortcut {
    const val MATCH_ID = 0
    const val MATCH_TEXT = 1

    const val EXE_TYPE_CLICK = 0

    const val DISPOSED_STATE_START = 0
    const val DISPOSED_STATE_SUCCESS = 1
    var core: JKShortcutCore? = null
    fun init(service: AccessibilityService) {
        core = JKShortcutCoreImpl(service)
    }

    //装载模块
    fun loadDisposedModule(modules: ArrayList<JKDisposedModule>) {
        core?.loadDisposedModule(modules)
    }

    //设置监听
    fun setListener(listener: JKShortcutListener) {
        core?.setListener(listener)
    }

    //设置事件执行间隔
    fun setEventIntervalTimeMillis(interval: Long) {
        core?.setEventIntervalTimeMillis(interval)
    }

    //设置点击之后的间隔
    fun setClickIntervalTimeMillis(interval: Long) {
        core?.setClickIntervalTimeMillis(interval)
    }

    //设置同一个页面执行模块最大次数
    fun setSameNameExeMaxCount(count:Int){
        core?.setSameNameExeMaxCount(count)
    }

    //最大递归层次
    fun setMaxRecursionTreeLayer(layer:Int){
        core?.setMaxRecursionTreeLayer(layer)
    }

    //无障碍事件分发
    fun event(event: AccessibilityEvent?) {
        if (BuildConfig.DEBUG) {
            val disposedTimeMillis = measureTimeMillis {
                core?.event(event)
            }
            JKShortcutLog.v("一次无障碍事件执行时间"){
                disposedTimeMillis.toString()
            }
        }else{
            core?.event(event)
        }
    }
}